﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>工序能力（无工时）看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    #queryInfo .el-form-item__label {
      color: #fff;
    }

    #datagrid .el-form-item {
      margin-bottom: 0px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">{{queryInfo.factoryname}}工序能力（无工时）看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        id="queryInfo">
        <el-form-item label="筛选时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="searchData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="exportData">导出</el-button>
          <el-button type="success" icon="el-icon-setting" size="small" @click="openInsertSpecItemsDialog">工序设置
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 柱状图区域 -->
      <el-row>
        <el-col :span="8">
          <dv-border-box-11 title="各数控工序占比" ref="specPieChart">
            <div style="height: 260px;padding-top: 40px;" id="specPieChart"></div>
          </dv-border-box-11>
        </el-col>
        <el-col :span="8">
          <dv-border-box-11 title="各工区数控序统计" ref="workcenterSpecBarChart">
            <div style="height: 260px;padding-top: 40px;" id="workcenterSpecBarChart"></div>
          </dv-border-box-11>
        </el-col>
        <el-col :span="8">
          <dv-border-box-11 title="各数控工序统计" ref="specBarChart">
            <div style="height: 260px;padding-top: 40px;" id="specBarChart"></div>
          </dv-border-box-11>
        </el-col>
      </el-row>

      <!-- 页面主表格 -->
      <dv-border-box-11 title="本月计划明细" ref="datagrid">
        <div id="datagrid" style="padding: 30px;padding-top:60px;padding-bottom:10px;">
          <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
            element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
            <el-table-column type="index" width="50px"></el-table-column>
            <el-table-column label="零件号" prop="subproductname" width="140" show-overflow-tooltip></el-table-column>
            <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
            <el-table-column label="主制工区" prop="workcentername" width="140" show-overflow-tooltip></el-table-column>
            <el-table-column label="工序名称" prop="workflowstepname" width="140" show-overflow-tooltip></el-table-column>
            <el-table-column label="计划开始" prop="startdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="计划完成" prop="enddate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="订单类型" prop="ordertype" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="计划类型" prop="plantype" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="派工人" prop="dispatchemployeename" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="派工时间" prop="dispatchdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="报工人" prop="reportemployeename" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="报工时间" prop="reportdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="检验员" prop="checkemployeename" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column label="检验时间" prop="checkdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="是否超期" prop="delaystatus" width="80" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag effect="dark" :type="scope.row.delaystatus === '否'?'success':'danger'">
                  {{scope.row.delaystatus}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="状态" prop="status" width="80" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag effect="dark" v-if="scope.row.status === '已完工'" type="success">已完工</el-tag>
                <el-tag effect="dark" v-else-if="scope.row.status === '待检验'" type="danger">待检验</el-tag>
                <el-tag effect="dark" v-else-if="scope.row.status === '待报工'">待报工</el-tag>
                <el-tag effect="dark" v-else type="info">待派工</el-tag>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.currentPage" :page-sizes="[queryInfo.pageSize,20,50,100]"
            :page-size="queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total" :total="total">
          </el-pagination>
          <el-backtop></el-backtop>
        </div>
      </dv-border-box-11>

      <!-- 数据钻取对话框 -->
      <el-dialog :title="chartDetail.title" :width="'98%'" :top="'10px'" :center="'center'"
        :visible.sync="chartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="零件号" prop="subproductname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
          <el-table-column label="主制工区" prop="workcentername" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="工序名称" prop="workflowstepname" width="140" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-popover trigger="click" placement="top">
                <p>
                  <i class="el-icon-user-solid" style="margin-right: 5px;"></i>派工人:
                  {{scope.row.dispatchemployeename}}
                </p>
                <p>
                  <i class="el-icon-time" style="margin-right: 5px;"></i>派工时间:
                  <span v-if="scope.row.dispatchdate">{{scope.row.dispatchdate.replace('T',' ')}}</span>
                </p>
                <p>
                  <i class="el-icon-user-solid" style="margin-right: 5px;"></i>报工人:
                  {{scope.row.reportemployeename}}
                </p>
                <p>
                  <i class="el-icon-time" style="margin-right: 5px;"></i>报工时间:
                  <span v-if="scope.row.reportdate">{{scope.row.reportdate.replace('T',' ')}}</span>
                </p>
                <p>
                  <i class="el-icon-user-solid" style="margin-right: 5px;"></i>检验人:
                  {{scope.row.checkemployeename}}
                </p>
                <p>
                  <i class="el-icon-time" style="margin-right: 5px;"></i>检验时间:
                  <span v-if="scope.row.checkdate">{{scope.row.checkdate.replace('T',' ')}}</span>
                </p>
                <div slot="reference" v-if="scope.row.workflowstepname">
                  <i class="el-icon-info" style="margin-right: 5px;"></i>{{scope.row.workflowstepname}}
                </div>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="计划开始" prop="startdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="计划完成" prop="enddate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="订单类型" prop="ordertype" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="计划类型" prop="plantype" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="是否齐套" prop="isallset" width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.isallset === '是'?'success':'danger'">
                {{scope.row.isallset}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="是否超期" prop="delaystatus" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag effect="dark" :type="scope.row.delaystatus === '否'?'success':'danger'">
                {{scope.row.delaystatus}}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="缺件情况" prop="missingpartsnotes" width="160" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="预齐套时间" prop="allsetplandate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag effect="dark" v-if="scope.row.status === '已完工'" type="success">已完工</el-tag>
              <el-tag effect="dark" v-else-if="scope.row.status === '待检验'" type="danger">待检验</el-tag>
              <el-tag effect="dark" v-else-if="scope.row.status === '待报工'">待报工</el-tag>
              <el-tag effect="dark" v-else type="info">待派工</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination @current-change="handleChartDetailCurrentChange"
          :current-page="chartDetail.queryInfo.currentPage" :page-sizes="[chartDetail.queryInfo.pageSize]"
          :page-size="chartDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="chartDetail.total">
        </el-pagination>
      </el-dialog>

      <!-- 工序参数设置--对话框 -->
      <el-dialog title="工序参数设置" :visible.sync="specItemsObj.dialogVisable" top="10px" width="70%">
        <!-- 表单 -->
        <el-form :model="specItemsObj.queryInfo" :inline="true">
          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model="specItemsObj.queryInfo.specname" placeholder="请输入" clearable></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" size="small" icon="el-icon-search" @click="getSpecItems">查询</el-button>
            <el-button type="success" size="small" icon="el-icon-circle-plus-outline"
              @click="addSpecItemObj.dialogVisable = true">添加</el-button>
          </el-form-item>
        </el-form>

        <!-- 表格 -->
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="specItemsObj.dataList" stripe border height="640">
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="操作" width="130">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="修改" placement="top-start">
                <el-button type="warning" icon="el-icon-edit" size="mini" @click="openUpdateSpecItemDialog(scope.row)">
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteData(scope.row)">
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="唯一id" prop="id" width="100" v-if="false"></el-table-column>
          <el-table-column label="工序" prop="specname" width="200" show-overflow-tooltip></el-table-column>
          <el-table-column label="启用状态" prop="status" width="100">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status" active-text="启用" inactive-text="" @change="changeStatus(scope.row)">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createemployee" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="创建时间" prop="createdate" width="160" :formatter="replaceDate"></el-table-column>
          <el-table-column label="修改人" prop="lastchangeemployee" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="修改时间" prop="lastchangedate" width="160" :formatter="replaceDate"></el-table-column>
        </el-table>
      </el-dialog>

      <!-- 添加工序--对话框 -->
      <el-dialog title="添加工序" :visible.sync="addSpecItemObj.dialogVisable" width="50%" @close="addDialogClosed">
        <el-form :model="addSpecItemObj.addSpecItemForm" :rules="addSpecItemObj.addSpecItemFormRule"
          ref="addSpecItemFormRef" :inline="true">
          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model="addSpecItemObj.addSpecItemForm.specname" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
        <!-- 弹出窗底下按钮 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addSpecItemObj.dialogVisable = false">取 消</el-button>
          <el-button type="primary" @click="addBtnConfirm" :loading="addSpecItemObj.loading">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 修改工序--对话框 -->
      <el-dialog title="修改工序" :visible.sync="updateSpecItemObj.dialogVisable" width="50%" @close="updateDialogClosed">
        <el-form :model="updateSpecItemObj.updateSpecItemForm" :rules="updateSpecItemObj.updateSpecItemFormRule"
          ref="updateSpecItemFormRef" :inline="true">
          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model="updateSpecItemObj.updateSpecItemForm.specname" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
        <!-- 弹出窗底下按钮 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="updateSpecItemObj.dialogVisable = false">取 消</el-button>
          <el-button type="primary" @click="updateBtnConfirm" :loading="updateSpecItemObj.loading">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { exportExcelData, getParams, getUserWhiteList } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    import { pieOption } from '../Scripts/hooks/pieChartConfig.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate, replaceDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate, replaceDate,
        currentTime: '',
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { factoryname: '', selectdate: '', currentPage: 1, pageSize: 7 },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff' },
        rules: { selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        dataList: [],
        // 各数控工序占比明细
        chartDetail: {
          dialogVisiable: false,
          queryInfo: { opdesc: '', workcentername: '', currentPage: 1, pageSize: 12 },
          dataList: [], title: '', total: 0
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        // 已维护工序
        specItemsObj: {
          dialogVisable: false,
          queryInfo: { selectOrg: [], specname: '' },
          dataList: []
        },
        // 添加工序
        addSpecItemObj: {
          dialogVisable: false,
          loading: false,
          addSpecItemForm: { specname: '', id: '' },
          addSpecItemFormRule: {
            specname: [{ required: true, message: '工序名称不能为空', trigger: 'blur' }]
          }
        },
        // 修改工序
        updateSpecItemObj: {
          dialogVisable: false,
          loading: false,
          updateSpecItemForm: { specname: '', id: '' },
          updateSpecItemFormRule: {
            specname: [{ required: true, message: '工序名称不能为空', trigger: 'blur' }]
          }
        }
      },
      methods: {
        // 各数控工序占比--饼图
        async getSpecPieChart() {
          const dom = document.getElementById("specPieChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getSpecPieChart', {
            type: 'getSpecPieChart',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let pieData = [], legendData = [];
          for (const item of data) {
            legendData.push(item.opdesc);
            pieData.push({ value: item.qty, name: item.opdesc });
          }

          let option = pieOption({ data: pieData });
          option.color = ['#0f6', '#90f', '#f60', '#f09', '#ff3', '#f33', '#FF6700'];
          const legend = { orient: 'vertical', x: '30', y: '30', data: legendData, textStyle: { color: '#fff' } };
          option.legend = { ...option.legend, ...legend };
          option.series[0].label.formatter = '{b}:{c} ({d}%)';
          option.series[0].center = ['60%', '50%'];

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.specPieChart.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            const { seriesName, name, value } = params;
            if (value == 0) { return; }
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.opdesc = name;
            this.chartDetail.queryInfo.workcentername = '';
            this.chartDetail.title = `【${name}】明细`;
            this.chartDetail.dialogVisiable = true;
            this.getDetails();
          })
        },
        // 各数控工序统计--柱状图
        async getSpecBarChart() {
          const dom = document.getElementById("specBarChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getSpecBarChart', {
            type: 'getSpecBarChart',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrSpec = [], arrQty = [];
          for (const i of data) {
            arrSpec.push(i.opdesc);
            arrQty.push(i.qty);
          }

          let option = barOption();
          option.grid = { left: '5%', right: '5%', bottom: '5%', containLabel: true };
          option.legend.data = [];//设置图例文字
          option.xAxis.data = arrSpec;
          option.yAxis[1].show = false;

          option.series[0].name = "工序";
          option.series[0].data = arrQty;
          option.series[0].label.color = colorList.blue.color;
          option.series[0].itemStyle.color.colorStops = colorList.blue.colorStops;

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.specBarChart.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            const { seriesName, name, value } = params;
            if (value == 0) { return; }
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.opdesc = name;
            this.chartDetail.queryInfo.workcentername = '';
            this.chartDetail.title = `【${name}】明细`;
            this.chartDetail.dialogVisiable = true;
            this.getDetails();
          })
        },
        // 各工区数控序统计--柱状图
        async getWorkcenterSpecBarChart() {
          const dom = document.getElementById("workcenterSpecBarChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getWorkcenterSpecBarChart', {
            type: 'getWorkcenterSpecBarChart',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrWorkcenter = [], arrQty = [];
          for (const i of data) {
            arrWorkcenter.push(i.workcentername);
            arrQty.push(i.qty);
          }

          let option = barOption({ isLableFormat: true, provideNumber: 4 });
          option.grid = { left: '5%', right: '5%', bottom: '5%', containLabel: true };
          option.legend.data = [];//设置图例文字
          option.xAxis.data = arrWorkcenter;
          option.yAxis[1].show = false;

          option.series[0].name = "总套数";
          option.series[0].data = arrQty;
          option.series[0].label.color = colorList.green.color;
          option.series[0].itemStyle.color.colorStops = colorList.green.colorStops;
          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.workcenterSpecBarChart.initWH(); chart.resize(); }, 300);
          chart.on('click', (params) => {
            const { seriesName, name, value } = params;
            if (value == 0) { return; }
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.workcentername = name;
            this.chartDetail.queryInfo.opdesc = '';
            this.chartDetail.title = `【${name}】明细`;
            this.chartDetail.dialogVisiable = true;
            this.getDetails();
          })
        },
        // 表格数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg) }
          this.dataList = data;
          this.total = total;
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.datagrid.initWH(); }, 300);
        },
        // 数据钻取明细
        async getDetails() {
          const { currentPage, pageSize } = this.chartDetail;
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getDetails', {
            type: 'getDetails',
            ...this.queryInfo,
            ...this.chartDetail.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg) }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        // 查询按钮点击
        searchData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) { return this.$message.error('必填项不能为空'); }
            this.getSpecPieChart();
            this.getSpecBarChart();
            this.getWorkcenterSpecBarChart();
            this.getData();
          })
        },
        // 导出主页面表格数据
        async exportData() {
          const config = {
            url: '../handler/board/GZCNCSpecDashBoardV2.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(pageSize) {
          this.queryInfo.pageSize = pageSize;
          this.getData();
        },
        handleChartDetailCurrentChange(newPage) {
          this.chartDetail.queryInfo.currentPage = newPage;
          this.getDetails();
        },
        // 查询已维护工序
        async getSpecItems() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=getSpecItems', {
            type: 'getSpecItems', ...this.specItemsObj.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.specItemsObj.dataList = data.map(item => {
            return { ...item, status: item.status === 1 }; //将【启用状态】由字符串变更为布尔值
          })
        },
        // 打开新增对话框
        async openInsertSpecItemsDialog() {
          const employeeid = getParams('uid');
          // 获取用户权限白名单
          const pageurl = window.location.pathname.split('/')[3];
          const whiteList = await getUserWhiteList(pageurl, this.$message);

          if (whiteList.indexOf(employeeid) === -1) {
            this.formDisabled = true;
            return this.$message.error('当前用户没有使用权限');
          }

          this.specItemsObj.dialogVisable = true;
          this.getSpecItems();
        },
        // 打开修改对话框
        openUpdateSpecItemDialog(row) {
          const { specname, id } = row;
          this.updateSpecItemObj.dialogVisable = true;
          this.updateSpecItemObj.updateSpecItemForm = { specname, id };
        },
        // 检查待新增工序是否已存在
        async checkIsExist(obj) {
          const { data: { data, meta, total } } = await axios({
            method: 'POST',
            url: '../handler/board/GZCNCSpecDashBoardV2.ashx?action=checkIsExist',
            data: { type: 'checkIsExist', ...obj }
          })
          return total > 0;
        },
        // 添加对话框[确认]点击
        addBtnConfirm() {
          this.$refs['addSpecItemFormRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              this.addSpecItemObj.loading = true;
              // 新增前 先判断 是否存在相同数据
              const isExist = await this.checkIsExist({ ...this.addSpecItemObj.addSpecItemForm });
              if (isExist) {
                this.addSpecItemObj.loading = false;
                return this.$message.error('数据已存在，不能重复添加');
              }

              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/board/GZCNCSpecDashBoardV2.ashx?action=insertData',
                data: { type: 'insertData', ...this.addSpecItemObj.addSpecItemForm, employeeid: getParams("uid") }
              });

              this.addSpecItemObj.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }

              if (total > 0) {
                this.$message.success('新增成功');
                this.addSpecItemObj.addSpecItemForm.specname = "";
                this.getSpecItems();
              } else {
                return this.$message.error('新增失败');
              }
            }
          });
        },
        // 修改对话框[确认]点击
        updateBtnConfirm() {
          this.$refs['updateSpecItemFormRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              this.updateSpecItemObj.loading = true;
              // 新增前 先判断 是否存在相同数据
              const isExist = await this.checkIsExist({ ...this.updateSpecItemObj.updateSpecItemForm });
              if (isExist) {
                this.updateSpecItemObj.loading = false;
                return this.$message.error('数据已存在，不能修改');
              }

              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/board/GZCNCSpecDashBoardV2.ashx?action=updateData',
                data: { type: 'updateData', ...this.updateSpecItemObj.updateSpecItemForm, employeeid: getParams("uid") }
              });

              this.updateSpecItemObj.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }

              if (total > 0) {
                this.$message.success('修改成功');
                this.updateSpecItemObj.dialogVisable = false;
                this.getSpecItems();
              } else {
                return this.$message.error('修改失败');
              }
            }
          });
        },
        // 删除数据
        async deleteData(row) {
          const { id } = row;
          // 更新启用状态前确认
          const confirmResult = await this.$confirm('是否确认删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)

          // 取消切换
          if (confirmResult !== 'confirm') { return this.$message.info('已取消删除'); }

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=deleteData', { type: 'deleteData', id });
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.$message.success('删除成功');
          this.getSpecItems();
        },
        // 切换启用状态
        async changeStatus(row) {
          const { id, status } = row;
          const confirmResult = await this.$confirm('是否切换启用状态?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)

          // 取消切换
          if (confirmResult !== 'confirm') {
            row.status = !row.status;
            return this.$message.info('已取消切换');
          }

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZCNCSpecDashBoardV2.ashx?action=changeStatus', {
            type: 'changeStatus', id, status, employeeid: getParams("uid")
          });

          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.$message.success('状态切换成功');
          this.getSpecItems();
        },
        // 添加对话框关闭后
        addDialogClosed() {
          this.addSpecItemObj.addSpecItemForm = { specname: '', id: '' }
          this.$refs['addSpecItemFormRef'].resetFields();
        },
        // 修改对话框关闭后
        updateDialogClosed() {
          this.updateSpecItemObj.updateSpecItemForm = { specname: '', id: '' }
          this.$refs['updateSpecItemFormRef'].resetFields();
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfThisMonth, endOfThisMonth];
        const factoryInfo = await getFactoryInfo({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是' });
        const { factoryid, factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.queryInfo.factoryid = factoryid;
        document.title = factoryname + '工序能力（无工时）看板';
        this.getSpecPieChart();
        this.getSpecBarChart();
        this.getWorkcenterSpecBarChart();
        this.getData();
      }
    })
  </script>
</body>

</html>